<template>
  <header>
    <div class="harder_main">
      <div class="harder_l">
        <h1 class="logo" @click="topBarChange('Home')">
          <img src="@/assets/img/logo.png" alt="">
        </h1>
        <ul class="navTop">
          <li :class="item.name == currentId?'active':''" v-for="item in topBar" :key="item.id"
            @click="topBarChange(item.name)">{{ item.title }}</li>
          <!-- <li>课程</li>
          <li>会员</li> -->
        </ul>
      </div>
      <div class="header_r">
        <div class="search">
          <input type="text" placeholder="搜索查询的课程">
          <!-- <i>图标</i> -->
          <el-icon color="#999" size='20'>
            <Search />
          </el-icon>
        </div>
        <div class="shop">
          <el-icon :size='20'>
            <ShoppingCart />
          </el-icon>

        </div>
        <div class="login"
        @click="toLogin"
        >登录/注册</div>
      </div>
    </div>
  </header>
</template>
<script setup>
//组件局部引入需要注册   全局需要下载
import { Search, ShoppingCart } from '@element-plus/icons-vue'
import {useUserStore} from '@/store/user'
const userStore = useUserStore()

import { getUserInfo} from '@/utils/api/login.js'


import {createToken} from '@/utils/api/createToken'

onBeforeMount(() => {
  //根据路由渲染顶部导航栏
  currentId.value = route.name;
//临时token
   createToken().then(
  (res)=>{console.log(res);
    let token  = res.data.token;
       getUserInfo(token).then((r)=>{
        console.log('双token验证',r);
        
      })

  
})


})


const topBar = ref([
  { id: 1, title: '首 页', name: 'Home' },
  { id: 2, title: '课 程', name: 'Course' },
  { id: 3, title: '会 员', name:'Vip'}
])
const currentId = ref('Home')
const router = useRouter()
const route =useRoute()
const topBarChange = (name)=>{
  console.log(name);
  router.push({
    name
  })
  
}

const toLogin =  ()=>{
  router.push({
    name:'Login'
  })
}



</script>
<style scoped lang='scss'>
header {
  width: 100%;
  height: 80px;
  z-index: 99;
  position: relative;
  // box-shadow: 0px 2px 4px rgba($color: #000000, $alpha: .6);
  box-shadow: 0 5px 6px rgb(0 0 0 / 16%)
}

.harder_main {
  width: 1000px;
  height: 80px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.navTop li:hover{
    cursor: pointer;
}
.logo{
    cursor: pointer;
  margin-right: 51px;
      width: 127px;
        height: 50px;
  img {
    width: 100%;
    height: 50px;
    }
}


.harder_l{
  display: flex;
  justify-content: space-between;
  align-items: center;
  ul {
      display: flex;      
	height: 50px;
      li{
        line-height: 50px;
        font-size: 16px;
        color: #808080;
      }
    }
    li:nth-child(-n+2){
        margin-right: 79px;
    }
}
// 选择效果
.active{
  position: relative;
  font-weight: 700;
  color: #3585ff !important;
}
.active::after{
  content: '';
  display: block;
  width: 140%;
  position: absolute;
  bottom: 0;
  left: -20%;
  height: 2px;
  background-color: #3585ff
}

.header_r{
  display: flex;
	align-items: center;
}
.header_r   .search {
    display: flex;
    align-items: center;
    padding: 0 10px;
    width: 300px;
    height: 43px;
    background: #F0F2F4;
    border-radius: 5px;

    input {
      width: 270px;
      height: 43px;
      border: none;
      background: transparent;
      outline: none;
    }
  }

.header_r .shop {
  display: flex;
  align-items: center;
  margin-left: 42px;
  margin-right: 39px;
}

.header_r .login {
  font-size: 16px;
  color: #808080;
  cursor: pointer;
}


</style>
